﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;

namespace URI_Demo
{
    class URI_Demo
    {
        static void Main(string[] args)
        {
            //Uri 对象统一资源标识符胡封装

            Uri uri = new Uri("http://www.baidu.com/");
            //应用Uri实例创建WebRequest

            WebRequest request = WebRequest.Create(uri);
            WebResponse response = request.GetResponse();
            Console.WriteLine("请求百度网址http://www.baidu.com/响应头:\n{0}", response.Headers);
            response.Close();


            Console.WriteLine("\n\n请求微软官网信息:http://www.mircosoft.com/en.us/default.aspx");
            Uri ms = new Uri("http://www.mircosoft.com/en.us/default.aspx");
            Console.WriteLine("协议主机名称:{0}", ms.Scheme);
            Console.WriteLine("URI主机部分:{0}", ms.Host);
            Console.WriteLine("URI端口号:{0}", ms.Port.ToString());
            Console.WriteLine("URI绝对路径:{0}", ms.AbsolutePath);
            Console.WriteLine("URI参数部分:{0}", ms.Query);
            Console.WriteLine("URI本地形式:{0}" ,ms.LocalPath);
            Console.ReadKey();
        }

    }
}
